package hwr.iamdr.Service;

import java.io.IOException;

import javax.servlet.http.*;
import javax.servlet.ServletException;

import com.google.appengine.api.datastore.*;

@SuppressWarnings("serial")
public class ActivationServlet extends HttpServlet
{
	static final DatastoreService dataStore	= DatastoreServiceFactory.getDatastoreService();

	@Override
	protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException
	{
		try
		{
			Key key	= KeyFactory.stringToKey(req.getParameter("key"));

			Entity entity	= dataStore.get(key);
			entity.setProperty("activated",true);
			entity.setProperty("Name",null);
			key	= dataStore.put(entity);

			req.getSession().setAttribute("UserLogin",KeyFactory.keyToString(key));
			resp.sendRedirect("/");
		}
		catch(Exception e)
		{
			resp.getWriter().write("Wrong format of Key,Dont hack!");
			resp.setStatus(0);
			e.printStackTrace();
			return;
		}
	}
}
